package math;

public class Operator extends Token{
	public static final char ADD = '+';
	public static final char SUB = '-';
	public static final char MULT = '*';
	public static final char DIV = '/';
	public static final char FAC  = '!';
	public static final char RPAR = ')';
	public static final char LPAR = '(';
	public static final  char POW = '^';
	public static final char[] operators = {ADD,SUB,MULT,DIV,FAC,RPAR,LPAR,POW,};
	char operator;
	boolean unary;
	
	public Operator(char op){
		super(op);
		operator = op;
		unary = false;
		if(op == FAC|op == RPAR){
			unary = true;
		}
	}
	
	public boolean isUnary(){
		return unary;
	}
	public void setUnary(Boolean stat){
		if(operator == SUB){
			unary = stat;
		}
	}
	public char getOperator(){
		return operator;
	}
	
	public int getPriorety(){
		if(unary == true){
			return 4;
		}else{
			switch(operator){
			case LPAR:
				return 0;
			case ADD:
				return 1;
			case SUB: 
					return 1;
			case MULT:
					return 2;
			case DIV:
					return 2;
			case POW:
					return 3;
			
			default:
					return -1;
			}
		}
	}
	
	public static boolean isOperator(char op){
		int i = 0;
		while(i < operators.length ){
			if(operators[i] == op){
				return true;
			}
			i++;
		}
		return false;
	}
}
